<?php

$params = call_user_func_array(['yii\helpers\ArrayHelper', 'merge'], [
    require __DIR__ . '/../../../common/config/params.php',
    require __DIR__ . '/../../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
]);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-frontend',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
        ],
        'response' => [
            'class' => 'yii\web\Response',
            'format' => \yii\web\Response::FORMAT_JSON,
            'on beforeSend' => function ($event) {
                $sender = $event->sender;
                $responseData = [
                    'code' => $sender->statusCode,
                    'msg' => 'Success',
                ];
                if ($sender->statusCode == 200) {
                    $responseData['data'] = $sender->data;
                } else {
                    $responseData['msg'] = $sender->data['message'];
                }
                $sender->statusCode = 200;
                $sender->data = $responseData;
            },
        ],
        'user' => [
            'identityClass' => 'frontend\models\User',
            'enableAutoLogin' => true,
            'enableSession' => false,
            'loginUrl' => null
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            //'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => require __DIR__ . '/restful.php',
        ],
    ],
    'params' => $params,
];
